<php> $this->display(tpl('head',true)); </php>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>栏目管理</legend>
</fieldset>
<div class="layui-row">
	<a class="layui-btn layui-btn-sm layui-btn-warm" href="/admin/category/add">添加栏目</a>
</div>
<style>
.layui-input {
    padding-left: 0;
}
.layui-form-checkbox {
    height: 20px;
    line-height: 20px;
    padding-right: 20px;
}
.layui-form-checkbox i {
    width: 25px;
    font-size: 18px;
}
</style>
<form class="layui-form" id="from" method="post" action="/admin/category/batch_action">
	<table class="layui-table">
		<thead>
			<tr>
				<th width="20"></th>
				<th width="50">排序</th>
				<th width="50">Id</th>
				<th>名称</th>
				<th>目录</th>
				<th style="text-align: center" width="70">类型</th>
				<th style="text-align: center" width="70">模型</th>
				<th style="text-align: center" width="70">记录集</th>
				<th width="260" style="text-align: center">操作</th>
			</tr>
		</thead>
		<tbody>
			<foreach array="Return">
			
			<php>
				$type= $row['type']==0 ? "栏目" :( $row['type']==1 ? "分类" : "单页");
				$curl=U(['cid'=>$row['cid']]);
			</php>
			<tr>
				<td>
					<input lay-skin="primary" name="iddb[]" value="{{$row['cid'] }}" type="checkbox">
				</td>
				<td>
					<input  class="layui-input center" name="reorder[{{$row['cid'] }}]" value="{{$row['reorder'] }}" type="text">
				</td>
				<td>{{$row['cid'] }}</td>
				<td>
					{{$row['levels'] }}<a class="onloading" target="_blank" href=" {{ $curl  }}">{{$row['name'] }}</a>
				</td>
				<td>{{$row['dir_name'] }}</td>
				<td style="text-align: center"><span class="badge badge-success">{{ $type }}</span></td>
				<td style="text-align: center">{{$row['modulenbname'] }}</td>
				<td style="text-align: center"><a class="onloading" href="/admin/articles/index/cid_{{$row['cid'] }}">{{$row['num'] }}</a></td>
				<td class="center">
					<a class="layui-btn layui-btn-sm " href="{{$curl }}" target="_blank"> <i class="fa fa-send"></i> 访问</a>
					
					<if condition="$row['type']===0">
					<a class="layui-btn layui-btn-sm layui-btn-normal" href="/admin/articles/add/cid_{{$row['cid'] }}"> <i class="fa fa-plus"></i> 添加内容</a>
					</if>
					<if condition="$row['type']===1">
					
					<a class="layui-btn layui-btn-sm bIndigo" href="/admin/category/add/cid_{{$row['cid'] }}"> <i class="fa fa-plus"></i> 添加子类</a>
					</if>							
					<a class="layui-btn layui-btn-sm layui-btn-warm" href="/admin/category/edit/cid_{{$row['cid'] }}"> <i class="fa fa-edit"></i> 修改</a>
					<a class="layui-btn layui-btn-sm layui-btn-danger" href="/admin/category/del/cid_{{$row['cid'] }}"> <i class="fa fa-edit"></i> 删除</a>
				</td>
			</tr>
			</foreach>			
		</tbody>
	</table>
	<div class="button">
		<button class="layui-btn layui-btn-sm layui-btn-warm" onclick="return all_checkbox_check('1')">全选</button>
		<button class="layui-btn layui-btn-sm layui-btn-warm" onclick="return all_checkbox_check('-1')">反选</button>
		<button class="layui-btn layui-btn-sm layui-btn-warm" onclick="return all_checkbox_check('0')">取消选择</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="step" value="reorder" >批量排序</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="step" value="power" >批量设置栏目</button>
	</div>
</form>
<script>
	function all_checkbox_check(type) {
		if(document.getElementsByClassName('layui-form-checkbox') != undefined && document.getElementsByClassName('layui-form-checkbox').length > 0) {
			var class_box = document.getElementsByClassName('layui-form-checkbox');
			var ids = document.getElementsByName('iddb[]');
			if(type == "1") { //全选
				for(var i = 0; i < class_box.length; i++) {
					$(ids[i]).prop("checked", true);
					$(class_box[i]).addClass("layui-form-checked");
				}
			} else if(type == "0") { //全不选
				for(var i = 0; i < class_box.length; i++) {
					$(ids[i]).prop("checked", false);
					$(class_box[i]).removeClass("layui-form-checked");
				}
			} else if(type == "-1") { //反选
				for(var i = 0; i < class_box.length; i++) {
					if(ids[i].checked == true) {
						$(ids[i]).prop("checked", false);
					} else {
						$(ids[i]).prop("checked", true);
					}
					$(class_box[i]).toggleClass("layui-form-checked");
				}
			}
		}
		return false;
	}
	layui.use(['form', 'layer'], function() {
		var form = layui.form,
			layer = layui.layer;

		form.on('switch(state)', function(obj) {
			if(obj.elem.checked == true) {
				var state = 1;
			} else {
				var state = 0;
			}
			$.ajax({
				url: "/admin/comment/state/",
				type: 'POST',
				data: {
					'state': state,
					'id': obj.elem.id
				},
				dataType: 'json',
				success: function(data) {
					if(obj.elem.checked == true) {
						layer.tips("已完成审核", obj.othis);
					} else {
						layer.tips("已取消审核", obj.othis);
					}
				}
			})
		});
	});
</script>
<php> $this->display(tpl('foot',true)); </php>  
